<template>
  <div class="meedu-main-body">
    <div class="float-left mb-30">
      <el-button @click="$router.push({ name: 'Addrole' })" type="primary">
        添加
      </el-button>
    </div>
    <div class="float-left">
      <el-table
        :header-cell-style="{ background: '#f1f2f9' }"
        :data="list"
        class="float-left"
      >
        <el-table-column prop="id" label="ID" width="120"> </el-table-column>
        <el-table-column prop="name" label="VIP"> </el-table-column>
        <el-table-column prop="expire_days" label="天数"> </el-table-column>
        <el-table-column label="价格">
          <template slot-scope="scope">
            <span> {{ scope.row.charge }}元 </span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="160">
          <template slot-scope="scope">
            <el-link type="danger" @click="deleteVIPItem(scope.row.id)"
              >删除
            </el-link>
            <el-link
              type="primary"
              class="ml-5"
              @click="
                $router.push({
                  name: 'Editrole',
                  query: {
                    id: scope.row.id,
                  },
                })
              "
              >编辑
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
    };
  },
  methods: {
    getRoleData() {
      this.$request.get("role").then((res) => {
        this.list = res.data.data;
      });
    },
    //删除会员
    deleteVIPItem(id) {
      this.$confirm("确认操作？", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$request
            .delete(`role/${id}`)
            .then((res) => {
              if (res.status == 500 || res.status == 1) {
                this.$message.error(res.message);
              } else {
                this.$message.success(this.$t("common.success"));
                this.getRoleData();
              }
            })
            .catch((e) => {
              this.$message.error(e.message);
            });
        })
        .catch(() => {
          // 点×不提示
        });
    },
  },
  created() {
    this.getRoleData();
  },
};
</script>

<style lang="less" scoped>
</style>
